// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 */
package edu.uwlax.cs.oayonlinestore.entities;

import java.util.Iterator;

/**
 * @see edu.uwlax.cs.oayonlinestore.entities.Order
 */
public class OrderImpl extends edu.uwlax.cs.oayonlinestore.entities.Order {
	private static final long serialVersionUID = -6881773613178743775L;

	public int calcItemCount() {
		int count = 0;
		if (getItems() != null)
			for (Iterator i = getItems().iterator(); i.hasNext();) {
				count += +((OrderItem) i.next()).getQuantity();
			}
		return count;
	}

	public float calcItemPrice() {
		float price = 0;
		if (getItems() != null)
			for (Iterator i = getItems().iterator(); i.hasNext();) {
				price += ((OrderItem) i.next()).calcTotalPrice();
			}
		return price;
	}

	public float calcShipping(float defaultShippingPrice) {
		return calcItemCount() * defaultShippingPrice;
	}

	public float calcTotalPrice(float tax, float defaultShippingPrice) {
		float TotalPrice = calcItemPrice();
		TotalPrice += calcShipping(defaultShippingPrice);
		TotalPrice += calcTotalTax(tax);

		if (getGiftCards() != null)
			for (Iterator i = getGiftCards().iterator(); i.hasNext();)
				TotalPrice -= ((GiftCard) i.next()).getMoneyValue();

		return TotalPrice;
	}

	public float calcTotalTax(float tax) {
		return calcItemPrice() * (tax / 100);
	}

}